package com.gexiaobao.pigeon.ui.dialog

import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import com.gexiaobao.pigeon.R
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

/**
 * created by : hxw
 * @date : 20221130
 * Describe :
 */
class BottomSharePictureDialog(private val bitmap: Bitmap) : BottomSheetDialogFragment() {

    /**
     * setStyle 圆角效果
     */
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NORMAL, R.style.BottomSheetDialog)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return inflater.inflate(R.layout.bottom_share_picture, container, false)
    }

    override fun onStart() {
        super.onStart()
        val ivSharePicture = dialog?.findViewById<AppCompatImageView>(R.id.ivSharePicture)
        val tvSure = dialog?.findViewById<AppCompatTextView>(R.id.tvSure)
        ivSharePicture?.setImageBitmap(bitmap)
        dialog?.findViewById<AppCompatTextView>(R.id.tvCancel)?.setOnClickListener {
            dismiss()
        }
        tvSure?.setOnClickListener {
            onShareClick?.setOnItemClickListener()
        }
        val bottomSheet = dialog?.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
        val layoutParams = bottomSheet?.layoutParams
        layoutParams?.height = ViewGroup.LayoutParams.MATCH_PARENT
        bottomSheet?.layoutParams = layoutParams
        BottomSheetBehavior.from(bottomSheet!!).state = BottomSheetBehavior.STATE_EXPANDED
    }

    interface OnClickSharePicture {
        fun setOnItemClickListener()
    }

    private var onShareClick: OnClickSharePicture? = null

    fun setOnShareClickListener(onShareClick: OnClickSharePicture) {
        this.onShareClick = onShareClick
    }
}